//获取节点的孩子节点
function classesLeftTreeGetChildren(record, panel) {
    if (record.get('leaf') == false && record.get('isHas') == 0) {
        var id = record.get('id');
        var depth = record.getDepth();
        var url;
        if (depth == 1)
            url = panel.depth2ChildrenUrl + record.data.id;
        else if (depth == 2)
            url = panel.depth3ChildrenUrl + record.data.id;
        else if (depth == 3)
            url = panel.depth4ChildrenUrl + record.data.id;
        else if (depth == 4)
            url = panel.depth5ChildrenUrl + record.data.parentId + '/' + record.data.status + '/' + record.data.id;
        else
            url = panel.depth6ChildrenUrl + record.data.status + '/' + record.data.id;
        Ext.Ajax.request({
            url: url,
            method: 'get',
            async: false, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
            success: function (response, opts) {
                var obj = Ext.decode(response.responseText);
                Ext.each(obj, function (node) {// 获得数据之后先将title的值赋值给text
                    node.text = node[panel.store.proxy.textField];
                    if (node.childrenCount == 0)//如果这个节点的可显示节点数量等于0则将此文件夹设置为不可展开
                        node.expandable = false;
                });
                record.appendChild(obj);
                if (record.data.leaf == false && record.data.expanded == false)
                    record.set('expanded', true);
                record.set("isHas", 1);
            },
            failure: function (response, opts) {
                var obj = Ext.decode(response.responseText);
                if (obj.code == 401 || obj.code == 402 || obj.code == 403)
                    Ext.Msg.alert("错误", obj.message);
                else
                    Ext.Msg.alert("错误", "该功能暂时不可用！");
            }
        });
    }
}

//点击树形菜单节点之后的操作
function classesTreeItemClick(record, panel) {
    Ext.getCmp('centerRegion').removeAll(false);
    classesNowDepth = record.getDepth();
    classesFormClean(record, panel.pattern);
    var data = classesGetDetailData(classesNowDepth, record, panel);
    classesPutDataInto(data, record);
    classesShowFormToCenter(record);
}

//将获取的数据填充到中心表单上
function classesPutDataInto(data, record) {
    var depth = record.getDepth(), type = record.data.status;
    if (depth == 1) {//如果是第一层的话,就是将班级信息覆盖写到表上
        classesDetailForm.down('#name').setValue(data.name);
        classesDetailForm.down('#creater').setValue(data.createrName);
        classesDetailForm.down('#creater').createrId = data.creater;
        classesDetailForm.down('#leader').setValue(data.leaderName);
        classesDetailForm.down('#leader').leaderId = data.leader;
        classesDetailForm.down('#stage').setValue('第' + data.stage + '期');
        classesDetailForm.down('#createDate').setValue(data.createDate.replace('T', '  '));
        classesDetailForm.down('#describe').setValue(data.describe);
        classesMemberGridStore.setData(data.members);
    } else if (depth == 2) {//如果是第二层的话,就是将组信息覆盖写到表上
        if (record.data.isCreate == 1)
            return;//如果是新建节点就不用填充数据了
        groupDetailForm.down('#name').setValue(data.name);
        groupDetailForm.down('#describe').setValue(data.describe);
        groupDetailForm.down('#createDate').setValue(data.createDate.replace('T', '  '));
        groupMemberGridStore.setData(data.members);
    } else if (depth == 3) {//如果是第三层的话,就是项目信息覆盖写到表上
        classesProjectDetailForm.down('#name').setValue(data.name);
        classesProjectDetailForm.down('#system').setValue(data.systemName);
        classesProjectDetailForm.down('#group').setValue(data.groupName);
        classesProjectDetailForm.down('#leadingCadre').setValue(data.leadingCadreName);
        classesProjectDetailForm.down('#describe').setValue(data.describe);
        classesProjectDetailForm.down('#createDate').setValue(data.createDate);
    } else if (depth > 4) {//如果是去填充复制节点的表单的话
        if (type == 0) {//如果是填充测试需求的表单的话
            classesCopyReqDetailForm.down('#testRequirementFormSystemDetailButton').projectId = data.project;//将对应的测试项目Id储存到下载按钮
            classesCopyReqDetailForm.down('#testRequirementFormTitle').setValue(data.title);
            classesCopyReqDetailForm.down('#testRequirementFormAuthor').setValue(data.author);
            classesCopyReqDetailForm.down('#testRequirementFormCreateDate').setValue(data.createDate);
            classesCopyReqDetailForm.down('#testRequirementFormUpdateDate').setValue(data.updateDate);
            classesCopyReqDetailForm.down('#detail').setValue(data.description);
            classesCopyReqTabPanel.down('#grade').setValue(data.grade);
        } else if (type == 1) {//如果是填充测试计划的表单的话
            //********************************基本信息填充begin****************************************//
            testDesignCopyDetailForm.down('#testDesignDetailFormTitle').setValue(data.title);
            testDesignCopyDetailForm.down('#testDesignDetailFormAuthor').setValue(data.author);
            testDesignCopyDetailForm.down('#testDesignDetailFormDescription').setValue(data.describe);
            testDesignCopyDetailForm.down('#testDesignDetailFormCreateDate').setValue(data.createDate);
            testDesignCopyDetailForm.down('#testDesignDetailFormUpdateDate').setValue(data.updateDate);
            //********************************基本信息填充end****************************************//
            if (data.leaf == 1) {//如果是文件夹的话就不用填充后面几个版块
                //********************************基本信息填充begin****************************************//
                testDesignCopyDetailForm.down('#testDesignDetailFormPriority').setValue(data.priority);
                //********************************基本信息填充end****************************************//
                //********************************测试步骤填充begin****************************************//
                testDesignStepCopyStore.removeAll();//setData之前要先removeAll,不然会堆栈溢出，原因不明
                var afterShotStep = testDesignCopyBorderShot(data.step);
                testDesignStepCopyStore.setData(afterShotStep);
                //********************************测试步骤填充end****************************************//
                //********************************关联需求填充begin****************************************//
                testDesignTestRequirmentCopyStore.removeAll();//setData之前要先removeAll,不然会堆栈溢出，原因不明
                testDesignTestRequirmentCopyStore.setData(data.testReq);
                //********************************关联需求填充end****************************************//
            }
            testDesignCopyTabPanel.down('#grade').setValue(data.grade);
        } else if (type == 2) {//如果是填充测试执行的表单的话
            testRunCopyDetailForm.down("#testRunDetailFormTitle").setValue(data.title);
            testRunCopyDetailForm.down("#testRunDetailFormAuthor").setValue(data.author);
            testRunCopyDetailForm.down("#testRunDetailFormPriority").setValue(data.priority);
            testRunCopyDetailForm.down('#testRunDetailFormTestDesign').setValue(data.testDesignName);
            testRunCopyDetailForm.down('#testRunDetailFormDescription').setValue(data.describe);
            testRunCopyDetailForm.down('#testRunDetailFormCreateDate').setValue(data.createDate);
            testRunCopyDetailForm.down('#testRunDetailFormUpdateDate').setValue(data.updateDate);
            //********************************基本信息填充end****************************************//
            //********************************测试步骤填充begin****************************************//
            if (record.data.leaf) {//如果是文件夹的话就不用填充后面几个版块
                //将执行记录结构体的内容取出来放到外层
                for (var i = 0, length = data.testRunLogDto.length; i < length; i++) {
                    //将执行记录结构体的内容取出来放到外层
                    data.testRunLogDto[i].id = data.testRunLogDto[i].testRunLog.id;
                    data.testRunLogDto[i].testRunId = data.testRunLogDto[i].testRunLog.testRunId;
                    data.testRunLogDto[i].host = data.testRunLogDto[i].testRunLog.host;
                    data.testRunLogDto[i].status = data.testRunLogDto[i].testRunLog.status;
                    data.testRunLogDto[i].duration = data.testRunLogDto[i].testRunLog.duration;
                    data.testRunLogDto[i].browserVersion = data.testRunLogDto[i].testRunLog.browserVersion;
                    data.testRunLogDto[i].os = data.testRunLogDto[i].testRunLog.os;
                    data.testRunLogDto[i].createDate = data.testRunLogDto[i].testRunLog.createDate;
                    data.testRunLogDto[i].testRunLog = null;
                    //将每个测试执行记录下的执行步骤进行排序
                    data.testRunLogDto[i].testRunLogStep = testDesignCopyBorderShot(data.testRunLogDto[i].testRunLogStep);
                }
                testRunLogStepRowWidGetStore.removeAll();
                testRunlogRowWidGetStore.removeAll();
                testRunlogRowWidGetStore.setData(data.testRunLogDto);// 不知为何使用add方式一个个加会堆栈溢出，只能使用setData()方式
            }
            testRunCopyTabPanel.down('#grade').setValue(data.grade);
        }
    }
}

//将中心界面的表单清空
function classesFormClean(record, pattern) {
    var depth = record.getDepth(), type = record.data.status;
    if (depth == 1) {//如果是去清空班级信息的表单的话
        classsDetailFormSetReadonly(pattern == 0);//将表单改为主任或者老师的操作形式
        classesDetailForm.reset();
        classesDetailForm.down('#creater').createrId = currentUserId;//班级谁建就是谁的,只有管理员可以修改
        classesDetailForm.down('#creater').setValue(currentUser);
        classesDetailForm.down('#leader').leaderId = null;
        classesMemberGridStore.removeAll();
        classesTabPanel.setActiveTab(0);
    } else if (depth == 2) {//如果是去清空组信息的表单的话
        classsGorupDetailFormSetReadonly(pattern == 1);//将表单改为主任或者老师的操作形式
        groupDetailForm.reset();
        groupMemberGridStore.removeAll();
        groupMemberGridCheckBox.deselectAll();
        groupTabPanel.setActiveTab(0);
    } else if (depth == 3) {//如果是去清空项目信息的表单的话
        classsProjectDetailFormSetReadonly(pattern == 1);//将表单改为主任或者老师的操作形式
        classesProjectDetailForm.reset();
    } else if (depth > 4) {//如果是去清空复制节点的表单的话
        classsCopyItemDetailFormSetReadonly(pattern == 1, type);//将表单改为主任或者老师的操作形式
        if (type == 0) {//如果是测试需求的节点的话
            classesCopyReqTabPanel.setActiveTab(0);
            classesCopyReqTabPanel.down('#grade').setValue(0);
            classesCopyReqDetailForm.reset();
        } else if (type == 1) {//如果是测试计划的节点的话
            testDesignCopyTabPanel.setActiveTab(0);
            if (record.data.leaf) {//如果是文件夹就只是显示一个tab就好了
                testDesignCopyTabPanel.tabBar.items.items[1].show();
                testDesignCopyTabPanel.tabBar.items.items[2].show();
                testDesignCopyTabPanel.tabBar.items.items[3].show();
            } else {
                testDesignCopyTabPanel.tabBar.items.items[1].hide();
                testDesignCopyTabPanel.tabBar.items.items[2].hide();
                testDesignCopyTabPanel.tabBar.items.items[3].hide();
            }
            testDesignCopyTabPanel.down('#grade').setValue(0);
            testDesignCopyDetailForm.reset();
            testDesignStepCopyStore.removeAll();
            testDesignTestRequirmentCopyStore.removeAll();
        } else if (type == 2) {//如果是测试执行的节点的话
            testRunCopyTabPanel.setActiveTab(0);
            if (record.data.leaf) {//如果是文件夹就只是显示一个tab就好了
                testRunCopyTabPanel.tabBar.items.items[1].show();
                testRunCopyTabPanel.tabBar.items.items[2].show();
            } else {
                testRunCopyTabPanel.tabBar.items.items[1].hide();
                testRunCopyTabPanel.tabBar.items.items[2].hide();
            }
            testRunCopyTabPanel.down('#grade').setValue(0);
            testRunCopyDetailForm.reset();
            testRunlogRowWidGetStore.removeAll();
            testRunLogStepRowWidGetStore.removeAll();
        }
        testCopyCheckLogStore.removeAll();
    }
}

//去获取对应的数据
function classesGetDetailData(depth, record, panel) {
    var url;
    if (depth == 1)
        url = panel.depth2ClickUrl + record.data.id;
    else if (depth == 2) {
        //判断这个是新建的小组节点还是编辑
        if (record.data.isCreate == 1)//新建节点就不用去那数据了
            return;
        url = panel.depth3ClickUrl + record.data.id;
    } else if (depth == 3)
        url = panel.depth4ClickUrl + record.data.id;
    else if (depth == 4) {//第四层如果点的是纯文件夹,就没有数据,但如果点的是叶子节点说明是测试分析
        if (record.get('leaf')) {//测试分析和测试bug是用store拿数据,所以不用下面的ajax拿数据
            if (record.get('text') == '测试分析') {
                trqAnalysisGrid.pattern = 1;//判断这个grid的projectId去哪里拿
                analysisGridStore.proxy.url = panel.analysisClickUrl + record.get('parentId') + '/root';
                analysisGridStore.reload();
            } else if (record.get('text') == '测试BUG') {
                testProjectBugGridStore.proxy.url = panel.bugClickUrl + record.get('parentId');
                testProjectBugGridStore.reload();
            }
        }
        return;
    } else if (depth > 4) {
        if (record.data.status == 0)//如果是测试需求的话
            url = panel.reqCopyClickUrl + record.data.id;
        else if (record.data.status == 1)//如果是测试计划的话
            url = panel.designCopyClickUrl + record.data.id;
        else if (record.data.status == 2)//如果是测试执行的话
            url = panel.runCopyClickUrl + record.data.id;
    }
    var result;
    Ext.Ajax.request({
        url: url,
        method: 'get',
        async: false, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        success: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (depth > 4) {
                obj.createDate = obj.createDate.replace('T', '  ');
                obj.updateDate = obj.updateDate.replace('T', '  ');
            }
            result = obj;
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 401 || obj.code == 402 || obj.code == 403)
                Ext.Msg.alert("错误", obj.message);
            else
                Ext.Msg.alert("错误", "该功能暂时不可用！");
        }
    });
    return result;
}

//将对应的中心表单显示到中心界面
function classesShowFormToCenter(record) {
    var depth = record.getDepth(), type = record.get('status');
    if (depth == 1)
        Ext.getCmp('centerRegion').add(classesTabPanel);
    else if (depth == 2)
        Ext.getCmp('centerRegion').add(groupTabPanel);
    else if (depth == 3)
        Ext.getCmp('centerRegion').add(classesProjectDetailForm);
    else if (depth == 4 && record.get('leaf')) {
        if (record.get('text') == '测试分析')
            Ext.getCmp('centerRegion').add(trqAnalysisGrid);
        else if (record.get('text') == '测试BUG') {
            Ext.getCmp('centerRegion').add(testProjectBugGrid);
            testProjectBugTabPanel.down('#grade').setHidden(false);
            testProjectBugTabPanel.down('#gradeButton').setHidden(false);
        }
    }//如果点击的是测试分析
    else if (depth > 4) {
        if (type == 0)//如果是显示测试需求的表单的话
            Ext.getCmp('centerRegion').add(classesCopyReqTabPanel);
        else if (type == 1)//如果是显示测试计划的表单的话
            Ext.getCmp('centerRegion').add(testDesignCopyTabPanel);
        else if (type == 2)//如果是显示测试执行的表单的话
            Ext.getCmp('centerRegion').add(testRunCopyTabPanel);
    }

}

//点击班级学生信息Grid的查看详成绩按钮之后
function classesSeeGradeClick(classesId, userId) {
    Ext.getCmp('centerRegion').removeAll(false);
    var url = zuulUrl + '/' + testServiceName + '/testProject/classes/group/project/grade/' + classesId + '/' + userId;
    classesGradeStore.proxy.url = url;
    classesGradeStore.reload();
    groupMemberGradeGrid.userId = userId;
    Ext.getCmp('centerRegion').add(groupMemberGradeGrid);
}

//点击组学生信息Grid的查看详成绩按钮之后
function groupSeeGradeClick(groupId, userId) {
    Ext.getCmp('centerRegion').removeAll(false);
    var url = zuulUrl + '/' + testServiceName + '/testProject/group/project/grade/' + groupId + '/' + userId;
    classesGradeStore.proxy.url = url;
    classesGradeStore.reload();
    groupMemberGradeGrid.userId = userId;
    Ext.getCmp('centerRegion').add(groupMemberGradeGrid);
}

//将测试计划的测试步骤进行排序
function testDesignCopyBorderShot(stepList) {
    var newArray = new Array();
    for (var i = 0; i < stepList.length; i++) {
        if (stepList[i].frontNode == 'begin') {
            newArray.push(stepList[i]);
            break;
        }
    }
    for (var i = 0; i < stepList.length - 1; i++) {
        for (var j = 0; j < stepList.length; j++) {
            if (newArray[i].backNode == stepList[j].id) {
                newArray.push(stepList[j]);
                break;
            }
        }
    }
    return newArray;
}

//给某个复制节点打分(或bug)
function gradeCopyItem(type, id, grade) {
    var url = zuulUrl + '/' + testServiceName + '/testProject/grade/';
    Ext.Ajax.request({
        url: type == 3 ? url + 'bug' : url + 'CopyItems',
        method: 'put',
        async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        params: type == 3 ? {
            id: id,
            grade: grade
        } : {
            type: type,//如果是给bug打分这个不好接收
            id: id,
            grade: grade,
            judge: currentUserId//如果是给bug打分这个不好接收
        },
        success: function (response, opts) {
            Ext.Msg.alert("成功", "打分成功");
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                Ext.Msg.alert("错误", obj.message);
            else
                Ext.Msg.alert("错误", "该功能暂时不可用！");
        }
    });
}

//给某个项目结算成绩
function settleGradeForProject(projectId) {
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/testProject/automaticSettleGrade',
        method: 'post',
        async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        params: {
            projectId: projectId
        },
        success: function (response, opts) {
            Ext.Msg.alert("成功", "结算完成,请前往班级(组)成员列表确认最终成绩");
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                Ext.Msg.alert("错误", obj.message);
            else
                Ext.Msg.alert("错误", "该功能暂时不可用！");
        }
    });
}

//通知组员某个项目的成绩公布了
function noticeGradeIsPublic(projectId) {
    Ext.Ajax.request({
        url: zuulUrl + '/' + testServiceName + '/testProject/noticeGradePublic',
        async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
        method: 'post',
        params: {
            projectId: projectId,
            userId: currentUserId
        },
        success: function (response, opts) {
            Ext.Msg.alert("成功", "通知成功");
        },
        failure: function (response, opts) {
            var obj = Ext.decode(response.responseText);
            if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                Ext.Msg.alert("错误", obj.message);
            else
                Ext.Msg.alert("错误", "该功能暂时不可用！");
        }
    });
}

//保存组的信息
function classesGroupSave() {
    if (groupDetailForm.isValid()) {
        if (groupMemberGridStore.getData().items.length == 0) {
            Ext.Msg.alert("错误", "该组没有设定组员！");
            return;
        }
        var result = new Object();
        var selectArray = classesLeftTreePanel.getSelectionModel().getSelected();// 得到被选择的行的数组.
        var isCreate = selectArray.items[0].data.isCreate;
        result['id'] = selectArray.items[0].data.id;
        result['name'] = groupDetailForm.down('#name').getValue();
        result['describe'] = groupDetailForm.down('#describe').getValue();
        result['classes'] = selectArray.items[0].data.parentId;
        var memberMap = new Object();
        var leaderCount = 0;
        Ext.each(groupMemberGridStore.getData().items, function (member) {
            if (member.data.isLeader == 1)//判断组员列表里面有没有组长
                leaderCount++;
            var userId = member.data.userId, isLeader = member.data.isLeader;
            memberMap[userId] = isLeader;
        });
        if (leaderCount != 1) {
            Ext.Msg.alert("错误", "该组没有设定组长或组长人数大于1！");
            return;
        }
        result['member'] = memberMap;
        Ext.Ajax.request({
            url: zuulUrl + '/' + authServiceName + '/group',
            method: isCreate == 1 ? 'post' : 'put',
            async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
            defaultXdrContentType: 'application/json',
            jsonData: JSON.stringify(result),
            success: function (response, opts) {
                selectArray.items[0].set('text', result['name']);//成功了的话要把树菜单的节点文本值更改为表单里填写的文本值
                selectArray.items[0].data.isCreate = 0;
                Ext.Msg.alert("成功", "保存成功");
            },
            failure: function (response, opts) {
                var obj = Ext.decode(response.responseText);
                if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                    Ext.Msg.alert("错误", obj.message);
                else
                    Ext.Msg.alert("错误", "该功能暂时不可用！");
            }
        });
    } else
        Ext.Msg.alert('错误', '组信息请填写完全！');
}

//点击添加小组之后的按钮
function classesGroupAddClick(panel) {
    var selectArray = classesLeftTreePanel.getSelectionModel().getSelected();// 得到被选择的行的数组.
    if (selectArray.length == 0 || selectArray.items[0].getDepth() != 1)
        Ext.Msg.alert("错误", "请选择班级节点！");
    else {
        var leftTreeItemId = Ext.create("MyApp.data.MyModelX").data.id.replace(
            /-/g, "");// 生成树节点Id
        //classesLeftTreeGetChildren(selectArray.items[0],panel);// 不能这样执行，不然在未展开的情况下去添加节点会跑到上面去
        var record = {// 构造新节点数据
            id: leftTreeItemId,
            text: '新小组',
            leaf: false,
            childrenCount: 0,
            expandable: false,
            parentId: selectArray.items[0].data.id,
            isCreate: 1
        };
        selectArray.items[0].appendChild(record);// 将新节点插入该节点之下
        selectArray.items[0].expand();// 展开该节点,这个会自动触发beforeitemexpand函数
        selectArray.items[0].data.isHas = 1;//因为已经自动展开过了，所以设置使其再次点击后不再去获取子节点
        var recordItem=panel.store.getById(leftTreeItemId);
        panel.getSelectionModel().select(recordItem);// 定位到新建节点
        Ext.getCmp('centerRegion').removeAll(false);
        classesFormClean(recordItem,panel.pattern);//0是老师，1是主任
        classesShowFormToCenter(recordItem);
    }
}

//点击删除小组之后的按钮
function classesGroupDeleteClick(panel) {
    var selectArray = panel.getSelectionModel().getSelected();// 得到被选择的行的数组.
    if (selectArray.length == 0 || selectArray.items[0].getDepth() != 2)
        Ext.Msg.alert("错误", "请选择要删除的小组节点！");
    else {
        Ext.MessageBox.confirm('删除', '是否要将该小组删除？此操作会将该小组下的所有内容清除！', function (btn) {
            if (btn === 'yes') {
                if (selectArray.items[0].data.isCreate != 1) {
                    Ext.Ajax.request({
                        url: zuulUrl + '/' + authServiceName + '/group/' + selectArray.items[0].data.id,
                        method: 'delete',
                        async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
                        success: function (response, opts) {
                            Ext.Msg.alert("成功", "删除成功");
                            var parentId = selectArray.items[0].data.parentId;
                            //console.log('儿子：'+panel.store.getNodeById(parentId).hasChildNodes());
                            selectArray.items[0].remove();// 将该节点及其子节点从store中移除
                            var parentNode = panel.store.getNodeById(parentId);
                            if (parentId != 'root' && !parentNode.hasChildNodes())
                                parentNode.set('expandable', false);
                            Ext.getCmp('centerRegion').removeAll(false);
                        },
                        failure: function (response, opts) {
                            var obj = Ext.decode(response.responseText);
                            if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                                Ext.Msg.alert("错误", obj.message);
                            else
                                Ext.Msg.alert("错误", "该功能暂时不可用！");
                        }
                    });
                } else {
                    var parentId = selectArray.items[0].data.parentId;
                    selectArray.items[0].remove();// 将该节点及其子节点从store中移除
                    var parentNode = panel.store.getNodeById(parentId);
                    if (parentId != 'root' && !parentNode.hasChildNodes())
                        parentNode.set('expandable', false);
                    Ext.getCmp('centerRegion').removeAll(false);
                }
            }
        });
    }
}

//将班级管理的班级详情表单的field设置readOnly(将表单改为主任或者老师的操作形式)
function classsDetailFormSetReadonly(readOnly) {
    classesDetailForm.down('#name').setReadOnly(readOnly);
    classesDetailForm.down('#chooseLeaderButton').setHidden(readOnly);
    classesDetailForm.down('#describe').setReadOnly(readOnly);
    classesTabPanel.down('#saveButton').setHidden(readOnly);
    classesTabPanel.down('#memberGrid').removeAll(false);
    if (readOnly) {//如果是老师的话
        classesTabPanel.down('#memberGrid').add(classesMemberGrid);
        groupMemberGradeGrid.getPlugin('editorPlugins').enable();

    } else {//如果是主任的话
        classesTabPanel.down('#memberGrid').add(classesMemberGridForDirector);
        groupMemberGradeGrid.getPlugin('editorPlugins').disable();
    }
}

//将班级管理的组表单的field设置readOnly(将表单改为主任或者老师的操作形式)
function classsGorupDetailFormSetReadonly(readOnly) {
    groupDetailForm.down('#name').setReadOnly(readOnly);
    groupDetailForm.down('#describe').setReadOnly(readOnly);
    groupTabPanel.down('#saveButton').setHidden(readOnly);
    groupTabPanel.down('#memberGrid').removeAll(false);
    if (readOnly) {//如果是主任的话
        groupTabPanel.down('#memberGrid').add(groupMemberGridForDirector);
        groupMemberGradeGrid.getPlugin('editorPlugins').disable();
    } else {//如果是老师的话
        groupTabPanel.down('#memberGrid').add(groupMemberGrid);
        groupMemberGradeGrid.getPlugin('editorPlugins').enable();
    }
}

//将班级管理的项目表单的field设置readOnly(将表单改为主任或者老师的操作形式)
function classsProjectDetailFormSetReadonly(readOnly) {
    classesProjectDetailForm.down('#settleGradeButton').setHidden(readOnly);
    classesProjectDetailForm.down('#noticeGradePublicButton').setHidden(readOnly);
}

//将班级管理的复制测试节点表单的field设置readOnly(将表单改为主任或者老师的操作形式)
function classsCopyItemDetailFormSetReadonly(readOnly, type) {
    if (type == 0)//如果是测试需求的话
        classesCopyReqTabPanel.down('#dockedItems').setHidden(readOnly);
    else if (type == 1)//如果是测试计划的话
        testDesignCopyTabPanel.down('#dockedItems').setHidden(readOnly);
    else if (type == 2)//如果是测试执行的话
        testRunCopyTabPanel.down('#dockedItems').setHidden(readOnly);
}

//但点击班级负责人选择按钮之后的操作
function classesChooseLeaderClick() {
    classesChooseClassesLeaderGridWin.show();
    classesChooseClassesLeaderGridStore.reload();
}

//点击新建班级之后的操作
function classesAddClassesClick(panel) {
    var leftTreeItemId = Ext.create("MyApp.data.MyModelX").data.id.replace(
        /-/g, "");// 生成树节点Id
    var record = {
        id: leftTreeItemId,
        text: '新节点',
        childrenCount: 0,
        expandable: false,
        parentId: 'root',
        isCreate: 1
    };// 构造新节点数据
    panel.getRootNode().appendChild(record);// 将该节点添加到根节点之下
    var recordItem = panel.store.getById(leftTreeItemId);
    panel.getSelectionModel().select(recordItem);// 定位到新建节点
    Ext.getCmp('centerRegion').removeAll(false);
    classesFormClean(recordItem,panel.pattern);//0是老师，1是主任
    classesShowFormToCenter(recordItem);
}

//点击删除班级的按钮之后
function classesDeleteClassesClick(panel) {
    var selectArray = panel.getSelectionModel().getSelected();// 得到被选择的行的数组.
    if (selectArray.length == 0 || selectArray.items[0].getDepth() != 1)
        Ext.Msg.alert("错误", "请选择要删除的班级节点！");
    else {
        Ext.MessageBox.confirm('删除', '是否要将该班级删除？此操作会将该班级的所有内容清除！', function (btn) {
            if (btn === 'yes') {
                if (selectArray.items[0].data.isCreate != 1) {
                    Ext.Ajax.request({
                        url: zuulUrl + '/' + authServiceName + '/classes/' + selectArray.items[0].data.id + '/' + currentUserId,
                        method: 'delete',
                        async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
                        success: function (response, opts) {
                            Ext.Msg.alert("成功", "删除成功");
                            selectArray.items[0].remove();// 将该节点及其子节点从store中移除
                            Ext.getCmp('centerRegion').removeAll(false);
                        },
                        failure: function (response, opts) {
                            var obj = Ext.decode(response.responseText);
                            if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                                Ext.Msg.alert("错误", obj.message);
                            else
                                Ext.Msg.alert("错误", "该功能暂时不可用！");
                        }
                    });
                } else {
                    selectArray.items[0].remove();// 将该节点及其子节点从store中移除
                    Ext.getCmp('centerRegion').removeAll(false);
                }
            }
        });
    }
}

//将班级管理的班级详情表单的field设置readOnly(将表单改为主任或者老师的操作形式)
function classsDetailFormSetReadonly(readOnly) {
    classesDetailForm.down('#name').setReadOnly(readOnly);
    classesDetailForm.down('#chooseLeaderButton').setHidden(readOnly);
    classesDetailForm.down('#describe').setReadOnly(readOnly);
    classesTabPanel.down('#saveButton').setHidden(readOnly);
    classesTabPanel.down('#memberGrid').removeAll(false);
    if (readOnly) {//如果是老师的话
        classesTabPanel.down('#memberGrid').add(classesMemberGrid);
        groupMemberGradeGrid.getPlugin('editorPlugins').enable();

    } else {//如果是主任的话
        classesTabPanel.down('#memberGrid').add(classesMemberGridForDirector);
        groupMemberGradeGrid.getPlugin('editorPlugins').disable();
    }
}

//点击班级信息保存之后要进行的操作
function classsesDetailSaveClick() {
    var leaderId = classesDetailForm.down('#leader').leaderId;
    if (classesDetailForm.isValid() && leaderId != null) {
        var result = new Object();
        var selectArray = classesLeftTreePanel.getSelectionModel().getSelected();// 得到被选择的行的数组.
        result['id'] = selectArray.items[0].data.id;
        result['name'] = classesDetailForm.down('#name').getValue();
        result['describe'] = classesDetailForm.down('#describe').getValue();
        result['creater'] = classesDetailForm.down('#creater').createrId;
        result['leader'] = leaderId;
        var memberArray = new Array();
        Ext.each(classesMemberGridStore.getData().items, function (member) {
            memberArray.push(member.data.id);
        });
        result['classesMember'] = memberArray;
        result['currentUserId'] = currentUserId;
        Ext.Ajax.request({
            url: zuulUrl + '/' + authServiceName + '/classes',
            method: selectArray.items[0].data.isCreate == 1 ? 'post' : 'put',
            async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
            defaultXdrContentType: 'application/json',
            jsonData: JSON.stringify(result),
            success: function (response, opts) {
                selectArray.items[0].set('text', result['name']);//成功了的话要把树菜单的节点文本值更改为表单里填写的文本值
                selectArray.items[0].data.isCreate = 0;
                Ext.Msg.alert("成功", "保存成功");
            },
            failure: function (response, opts) {
                var obj = Ext.decode(response.responseText);
                if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                    Ext.Msg.alert("错误", obj.message);
                else
                    Ext.Msg.alert("错误", "该功能暂时不可用！");
            }
        });
    } else
        Ext.Msg.alert('错误', '班级信息请填写完全！');
}

